import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter_utils/flutter_utils.dart';
import 'package:shared_preferences/shared_preferences.dart';

void main() {
  TestWidgetsFlutterBinding.ensureInitialized();
  setUpAll(() {
    SharedPreferences.setMockInitialValues(<String, Object>{});
  });
  test('feedbackSoundEffectIndex', () async {
    var key = 'feedbackSoundEffectIndex';
    final stream1 = SharedPreferenceService.instance.getStream<int>(key, 0);

    stream1.listen((event) {
      debugPrint('listen1 event===$event');
    }, onError: (e, trace) {
      debugPrint('listen1 onError $e $trace');
    }, onDone: () {
      debugPrint('listen1 onDone');
    });
    await Future.delayed(const Duration(milliseconds: 100));
    debugPrint('set feedbackResourceIndex = 0');
    SharedPreferenceService.instance.set(key, 0);
    await Future.delayed(const Duration(milliseconds: 100));
    debugPrint('listen2');
    stream1.listen((event) {
      debugPrint('listen2 event===$event');
    });
    await Future.delayed(const Duration(milliseconds: 100));
    debugPrint('set feedbackResourceIndex = 1');
    SharedPreferenceService.instance.set(key, 1);
    await Future.delayed(const Duration(milliseconds: 100));
    debugPrint('set feedbackResourceIndex = 2');
    SharedPreferenceService.instance.set(key, 2);
    await SharedPreferenceService.instance.clear();
  });
}
